package com.eco.fanliapp.admin.controller.web;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eco.fanliapp.admin.annotation.SysLogAnnotation;
import com.eco.fanliapp.admin.common.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppGoodsMapper;
import com.eco.fanliapp.dao.GoodsFreeMapper;
import com.eco.fanliapp.dao.SyChannelGoodsMapper;
import com.eco.fanliapp.dao.SyTljGoodsfreeMapper;
import com.eco.fanliapp.entity.AppGoods;
import com.eco.fanliapp.entity.GoodsFree;
import com.eco.fanliapp.entity.SyChannelGoods;
import com.eco.fanliapp.entity.SyTljGoodsfree;
import com.eco.fanliapp.service.*;
import com.eco.fanliapp.utils.BigDecimalUtils;
import com.eco.fanliapp.utils.DateFormatUtils;
import com.eco.fanliapp.utils.DateUtils;
import com.eco.fanliapp.utils.UUIDUtils;
import com.eco.fanliapp.vo.HaoDanKuItemInfo;
import com.eco.fanliapp.vo.TbkItemInfoGetInfo;
import com.eco.fanliapp.vo.TbkPrivilegeGetInfo;
import com.github.pagehelper.PageInfo;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;


/**
 * <p>
 * 渠道商品对照表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-11-04
 */
@RestController
@RequestMapping("/web/syChannelGoods")
public class SyChannelGoodsController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(SyChannelGoodsController.class);
    @Autowired
    private ISyChannelGoodsService syChannelGoodsService;
    /**
     * 单渠道商品列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/selectSyChannelGoods")
    public ServerResponse<PageInfo> selectSyChannelGoods(@RequestParam(defaultValue = "1") Integer pageNum,
                                                         @RequestParam(defaultValue = "10") Integer pageSize) {
        logger.info("进入/selectSyChannelGoods");
        return syChannelGoodsService.selectSyChannelGoods(pageNum, pageSize);
    }


    @SysLogAnnotation(value = "删除单独分佣商品", userType = 2)
    @GetMapping(value = "/delectSyChannelGoods")
    public ServerResponse delectSyChannelGoods(Long tableId,Long itemId) {
        logger.info("进入/delectSyChannelGoods");
        int i = syChannelGoodsService.delectSyChannelGoods(tableId,itemId);
        if (i == 0) {
            return ServerResponse.createByErrorMessage("删除失败");
        }
        return ServerResponse.createBySuccessMessage("删除成功" + i);
    }


    @SysLogAnnotation(value = "添加单独分佣商品", userType = 2)
    @PostMapping(value = "/addSyChannelGoods")
    public ServerResponse addSyChannelGoods(@RequestBody SyChannelGoods syChannelGoods) {
        logger.info("进入/addSyChannelGoods");
        return syChannelGoodsService.addSyChannelGoodsNew(syChannelGoods,getAuthentication().getCompanyId());
    }


    @SysLogAnnotation(value = "修改单独分佣商品", userType = 2)
    @PostMapping(value = "/updateSyChannelGoods")
    public ServerResponse updateSyChannelGoods(@RequestBody SyChannelGoods syChannelGoods) {
        logger.info("进入/updateSyChannelGoods");
        try {
            return  syChannelGoodsService.updateSyChannelGoodsNew(syChannelGoods);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("修改失败");
        }
        return ServerResponse.createByErrorMessage("修改失败");
    }


    @GetMapping(value = "/getSyChannelGoodsByItemId")
    public ServerResponse getSyChannelGoodsByItemId(String itemId) {
        logger.info("进入/getSyChannelGoodsByItemId");

        SyChannelGoods syChannelGoodsByItemId = syChannelGoodsService.getSyChannelGoodsByItemId(Long.valueOf(itemId));
        if (syChannelGoodsByItemId == null) {
            return ServerResponse.createByErrorMessage("查无信息");
        }
        return ServerResponse.createBySuccess(syChannelGoodsByItemId);
    }

}
